package com.magist.manage.copyrights.service.impl;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.magist.core.entity.Page;
import com.magist.core.service.SimpleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import tk.mybatis.mapper.entity.Example;

import com.magist.manage.copyrights.dao.ContractBalanceMapper;
import com.magist.manage.copyrights.entity.ContractBalance;
import com.magist.manage.copyrights.service.ContractBalanceService;

@Service
public class ContractBalanceServiceImpl extends SimpleServiceImpl<ContractBalance> implements ContractBalanceService {

    @Autowired
    private ContractBalanceMapper contractBalanceMapper;

    @Override
    public PageInfo<ContractBalance> page(Example example, Page page) {
        PageHelper.startPage(page.getCurrPage(), page.getLimit());
        List<ContractBalance> list = this.find(example);
        PageInfo<ContractBalance> pageInfo = new PageInfo(list);
        return pageInfo;
    }

    @Override
    public ContractBalance getByContractId(String contractId) {
        Example example = new Example(ContractBalance.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("deleted", "F");
        criteria.andEqualTo("contractId", contractId);

        List<ContractBalance> contractBalances = this.find(example);
        if (CollectionUtils.isEmpty(contractBalances)) {
            return null;
        }
        return contractBalances.get(0);

    }
}